package com.tianhua.javs.client.enums;

/**
 * Description:
 * date: 2022/2/9
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
public enum BusinessKeyWardEnum implements KeyWardEnum{
    BO("bo","业务对象或者领域对象",false),
    DO("do","数据库对象",false),
    DTO("dto","数据库传输对象",false),
    CMD("cmd","命令对象",false),
    EVENT("event","事件对象",false),
    MSG("msg","消息对象",false),

    MAPPER("mapper","do对应的数据库操作DAO对象",false),
    PUBLISHER("publisher","事件发布对象",false),
    FACTORY("factory","工厂对象",false),
    EXECUTOR("executor","执行器对象",false),
    GATAWAY("gataway","领域网关对象",false),
    REPOSITORY("repository","聚合仓储对象",false),
    SERVICE("service","服务对象",false),


    CONVERT_BO("convertbo","dto或者do的转换方法将其转换为bo对象",true),
    CONVERT_DTO("convertdto","bo的转换方法将其转换为dto对象",true),
    CONVERT_DO("convertdo","bo的转换方法将其转换为do对象",true),
    CONVERT_EVENT("convertevent","cmd对象或者bo对象转换为event对象",true),


    CONVERT_BOS("convertbos","dto或者do的转换方法将其转换为bo对象",true),
    CONVERT_DTOS("convertdtos","bo的转换方法将其转换为dto对象",true),
    CONVERT_DOS("convertdos","bo的转换方法将其转换为do对象",true),
    CONVERT_EVENTS("convertevents","cmd对象或者bo对象转换为event对象",true),
    ;

    private String code;
    private String desc;
    private Boolean withFunction;
    private String templateCode;

    BusinessKeyWardEnum(String code, String desc, Boolean withFunction){
        this.code = code;
        this.desc = desc;
        this.withFunction = withFunction;
    }

    @Override
    public String getKeyWardCode() {
        return code;
    }

    @Override
    public String getKeyWardDesc() {
        return desc;
    }

    @Override
    public boolean withFunction() {
        return withFunction;
    }

    @Override
    public String templateCode() {
        return null;
    }

    /**
     * 判断是否是业务关键字
     * @param varCode
     * @return
     */
    public static boolean isBusinessKeyWard(String varCode){
        for (BusinessKeyWardEnum businessKeyWardEnum : BusinessKeyWardEnum.values()){
            if(businessKeyWardEnum.getKeyWardCode().equals(varCode)){
                return true;
            }
        }
        return false;
    }

    /**
     * 判断是否是javs模型
     * @param className
     * @return
     */
    public static boolean isJavsModel(String className){
        String name = className.toLowerCase();
        return name.endsWith(BO.getKeyWardCode())
                || name.endsWith(DTO.getKeyWardCode())
                || name.endsWith(DO.getKeyWardCode())
                || name.endsWith(CMD.getKeyWardCode())
                || name.endsWith(EVENT.getKeyWardCode())
                || name.endsWith(MSG.getKeyWardCode());
    }

}
